package cn.hiapi.shopkeeper.service.activity;

import cn.hiapi.basic.ResUtils;
import cn.hiapi.basic.jpa.pageable.QueryWrapper;
import cn.hiapi.basic.service.AbsBasicService;
import cn.hiapi.shopkeeper.entity.activity.ActivityOther;
import cn.hiapi.shopkeeper.jpa.activity.ActivityOtherJpa;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author AdinZ
 * @date 2022/12/30 14:49
 */
@Service
public class ActivityOtherService extends AbsBasicService<ActivityOtherJpa, ActivityOther, Long> {

    /**
     * 删除指定活动的其他设置
     *
     * @param aid
     * @return
     */
    @Transactional
    public int deleteByAid(long aid) {
        return ResUtils.getDefault(this.repository.deleteByAid(aid));
    }

    public ActivityOther getByAid(long aid) {
        List<ActivityOther> others = this.findList(new QueryWrapper().eq("aid", aid));
        if (others.isEmpty()) return null;
        return others.get(0);
    }
}
